test: rewrite tests with Apollo MockedProvider #85
+587
−86
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #33
Summary
After switching from Open Library to our GraphQL API, the page tests were removed and 11 of the remaining 25 component tests failed. This PR makes
pnpm testpass again and adds page tests using Apollo'sMockedProvider, so no real requests are sent to the backend.Changes
Outdated component tests fixed
SearchBar,BookFilters: use thegenressearch param (renamed fromgenre).BookPagination: rewritten for link-based pagination. Also checks that the search and filters are kept when changing page.BookCard: rendered withMockedProvider, snapshot regenerated.FavoriteButton: rewritten for favorites stored in the backend. A logged out user gets the login dialog, a logged in user can add and remove favorites, and an error message is shown when saving fails.New page tests
home.test.tsx: shows results from the API, sends search/filters/sort/page as variables to the API (so filtering and sorting happen on the whole result set), empty result, API error, and opening a book and going back to the same search.selectedBook.test.tsx: shows book details, "Book Not Found", and browsing to the next book.Helpers in
app/test/:renderRoutes(router +MockedProvider),mocks(GraphQL responses) andsession(logged in/out session for the mocked auth client).useSearchBooksanduseBooknow export their queries so tests can mock them. No other app code is changed.How to test
cd frontend
pnpm test
35/35 tests pass. Lint and Prettier are clean.
Notes
Unknown query named "FavoriteBooks" requested in refetchQueriesin the favorite tests is expected. Apollo only refetches queries that are mounted, and the favorites list (profile page) isn't mounted in the test. It's a dev-only warning.role="button"by the Button component, so the test looks it up as a button. It should probably be a plain link; that's for a separate PR.AI usage
The tests and this description were generated with AI (Claude) and reviewed by the PR author before opening the PR.